﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		
		<title>jb-aptech毕业设计项目</TITLE>
<meta name="renderer" content="ie-comp">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="../../css/style.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="../../css/menu.css">

		<script src="../../script/jquery-3.3.1.min.js"></script>
		<script src="../../script/common.js"></script>
		<script src="../../../js/bootstrap.min.js"></script>
		<script src="../../../js/vue.js"></script>
	</head>
  
  <body>
  <div id="roleright">
    <div class="page_title">
			权限管理 > 用户管理 > 系统角色管理 > 权限分配
	</div>
			<table class="query_form_table">
				<tr>
					<th>角色名</th>
					<td>{{role.role_name}}</td>
					<th>角色描述</th>
					<td>{{role.role_desc}}</td>
					<th>状态</th>
					<td><span v-if=" role.role_flag==1">正常</span>
						<span v-if=" role.role_flag==0">禁止</span></td>
				</tr>
				<tr>
					<th>权限</th>
					<td colspan="5" align="center">
						<input type="reset" value="取消" @click="qx()" class="common_button">
						<input type="button" @click="save()" value="保存" class="common_button">
					</td>
				</tr>
			</table>
			<br/>
			<table class="query_form_table">
				
					<tr>
						<td>

					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="checkbox" @change="selSup()" id="acc">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						 <hr>

						<div v-for="m in might" v-if="m.might_parent_code==0">
						 <div style="background-color:#CCCCCC;">
						  &nbsp;&nbsp;&nbsp;{{m.might_text}}
						<input type="checkbox" v-model="m.isok" @change="panduan()">
					</div><br>
							<span v-for="sub in might" v-if="sub.might_parent_code==m.might_code">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								{{sub.might_text}}
									<input type="checkbox" v-model="sub.isok"  @change="panduan()">
							</span>
						 <hr>
						</div>
					</td>
				</tr>
			</table>
  </div>
  </body>
<script>
	var app = new Vue({
		el:'#roleright',
		data:{
            role:{
                role_id:'',
                role_name:'',
                role_desc:'',
                role_flag:'',
            },
			might:[],
		},
		methods:{
			save(){
			    $.getJSON("/deletesys_role_rightbyrid/"+this.role.role_id,function (json) {
                    $.each(app.might,function (i) {
                        if(this.isok==1){
                           		 $.getJSON("/insertsys_role_right",{"roleid":app.role.role_id,"value":this.might_code},function (json) {
                            	 });
                        }
                    });
                    alert("修改成功")
                });
			},
            selSup(){
				var acc = document.getElementById("acc");
					if(acc.checked==true){
                        $.each(this.might,function (i) {
                            this.isok=1;
                        });
					}
					if(acc.checked==false){
                        $.each(this.might,function (i) {
                            this.isok=0;
                        });
					}
            	},
			qx(){
                $.getJSON("/selectallrolebymight",{"id":app.role.role_id},function (json) {
                    app.might=json.data.obj;
                    var a = true;
                    $.each(app.might,function (i) {
                        if(this.isok!=1){
                            a=false;
                            return;
                        }
                    });
                    if(a!=false){
                        document.getElementById("acc").checked=true;
                    }else {
                        document.getElementById("acc").checked=false;
                    }
                });
			},
            panduan(){
                var a = true;
                $.each(app.might,function (i) {
                    if(this.isok!=1){
                        a=false;
                        return;
                    }
                });
                if(a!=false){
                    document.getElementById("acc").checked=true;
                }else {
                    document.getElementById("acc").checked=false;
				}
            }
        },
		created(){
		    let id = sessionStorage.getItem("rid");
		    $.getJSON("/querySysRoleById/"+id,function (json) {
				app.role=json.data.obj;
            });
		    $.getJSON("/selectallrolebymight",{"id":id},function (json) {
				app.might=json.data.obj;
                var a = true;
                $.each(app.might,function (i) {
                    if(this.isok!=1){
                        a=false;
                        return;
                    }
                });
                if(a!=false){
                    document.getElementById("acc").checked=true;
                }else {
                    document.getElementById("acc").checked=false;
                }
            });
		}
	})
</script>
</html>
